#######################################################################################
# Basic
##

# set prefix: Ctrl + x
set -g prefix C-x
unbind C-b

# split window
unbind '"'  
bind - splitw -v   
unbind %  
bind | splitw -h 

# resize window
bind k resizep -U 10    
bind j resizep -D 10   
bind h resizep -L 10   
bind l resizep -R 10 

# these four options is not only available brefore tmux 2.1
if-shell '[[ `tmux -V | cut -d" " -f2` < 2.1 ]]' \
  "set-window-option -g mode-mouse on"
if-shell '[[ `tmux -V | cut -d" " -f2` < 2.1 ]]' \
  "set-window-option -g mouse-resize-pane on"
if-shell '[[ `tmux -V | cut -d" " -f2` < 2.1 ]]' \
  "set-window-option -g mouse-select-pane on"
if-shell '[[ `tmux -V | cut -d" " -f2` < 2.1 ]]' \
  "set-window-option -g mouse-select-window on"

# this option is only available in tmux 2.1+
if-shell '[[ `tmux -V | cut -d" " -f2` == 2.1 ]] || [[ `tmux -V | cut -d" " -f2` > 2.1 ]]' \
  "set-window-option -g mouse on"

# set vi as copy-mode 
set-window-option -g mode-keys vi

# VI-style copy/paste (http://jasonwryan.com/blog/2011/06/07/copy-and-paste-in-tmux/)
# unbind-key [
bind-key Escape copy-mode
unbind-key p
bind-key p paste-buffer
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-selection
bind-key -t vi-copy C-v rectangle-toggle

# fix vim paste bug for vim + tmux
# brew install reattach-to-user-namespace
set-option -g default-command "reattach-to-user-namespace -l bash"

#######################################################################################
# Status bar
##

# status-utf8 option is only availabe before tmux 2.2
if-shell '[[ `tmux -V | cut -d" " -f2` < 2.2 ]]' \
  "set-option -g status-utf8 on"

set-option -g status-interval 60
set-option -g status-left "#[fg=green]S:#S #[fg=yellow]W:#I #[fg=cyan]P:#P"
set-option -g status-left-length 30
# status line variables document http://linux.die.net/man/3/strftime
set-option -g status-right "#{prefix_highlight} #[fg=cyan]#(date +'%Y-%m-%d %H:%M') " # right part: time lisk 23:59
set-option -g status-right-length 30 # more space left for center part (window names)
set-option -g status-justify centre

set-option -g window-status-format '#I:#W'
set-option -g window-status-current-format '[#I:#W*]'
set-window-option -g window-status-current-fg red
set-window-option -g window-status-current-bg default
set-window-option -g window-status-current-attr bright

# start windows and panes at 1, not 0
set-option -g base-index 1
set-window-option -g pane-base-index 1

# let the window be renamed automatically when launching a process
# but prevent renaming once you have manually changed it.
set-option -g allow-rename off

# window status style
# set-window-option -g window-status-current-bg blue
# set-window-option -g window-status-current-fg green

# pane border style
set-option -g pane-border-bg default
set-option -g pane-border-fg blue
set-option -g pane-active-border-bg default
set-option -g pane-active-border-fg red

# set status background and foreground color
set-option -g status-bg default
set-option -g status-fg white

#######################################################################################
# Plugins
##

# list of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'

# save and load session
# https://github.com/tony/tmuxp/
# sudo pip install tmuxp
# tmuxp save [session]
# tmuxp load [session]

# initialize tmux plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
